// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#ifndef TYPE_DEFINITION
#define TYPE_DEFINITION
typedef unsigned __int8 BYTE;
typedef unsigned __int16 WORD;
typedef unsigned __int32 DWORD;
typedef unsigned __int64 QWORD;

typedef void  *LPVOID;
typedef BYTE  *LPBYTE;
typedef WORD  *LPWORD;
typedef DWORD *LPDWORD;
typedef QWORD *LPQWORD;

typedef unsigned char uchar;
typedef BYTE byte;

typedef unsigned short word;
typedef void (*putcf) (void* ,char);

extern "C" __inline BYTE __declspec(naked) inb(register WORD port)
{
	__asm	push  edx		
	__asm   mov   ax, port
	__asm	in    ax, dx	
	__asm   movzx eax, dl		
	__asm	pop	  edx			
}

extern "C" __inline void __declspec(naked) outb(register WORD portNo, register BYTE value)			
{
	__asm push dx			
	__asm push ax			

	__asm mov al, value		
	__asm mov dx, portNo	
	__asm out dx, al		

	__asm pop ax			
	__asm pop dx
}
#endif //TYPE_DEFINITION

#include "IDT.h"

extern "C"
{
	void kfail(char* pFmt, ...);

	void detect_cpu(void) ;

	void InitGDB(IDT* idt);

	QWORD GetTicksCount();

	void reboot();
	void halt();

	int xstrlen(const char* pStr);
	char* xstrcpy(char* pStrDst, char* pStrSrc);

	void xprintf(char* format, ...);
	void init_printf(void* putp, void (*putf) (void*,char));

	int a2d(char ch);

	void xmemcpy(LPVOID pSrcArg, LPVOID pDestArg, DWORD size);

	void xmemset_b(LPVOID pSrcArg, BYTE value, DWORD size);
	void xmemset_w(LPVOID pSrcArg, WORD value, DWORD size);
	void xmemset_d(LPVOID pSrcArg, DWORD value, DWORD size);

	#define ZeroMemory(pSrcArg, size) xmemset(pSrcArg, 0, size)


	void LoadCoreCode();

	void PrepaireLongModeEnvironment();
	void PrecompileCoreForX64();
	void ExecuteX64Core();

	void PrepaireProtectedModeEnvironment();
	void PrecompileCoreForX86();
	void ExecuteX86Core();
}
#define NULL 0
